<template>
  <div>
    <h1>实时选股监控</h1>
    <el-table :data="stocks" style="width: 100%">
      <el-table-column prop="name" label="股票名称" width="180" />
      <el-table-column prop="symbol" label="代码" width="120" />
      <el-table-column prop="change_percent" label="涨幅(%)" width="120" />
      <el-table-column prop="volume" label="成交量" />
    </el-table>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'

const stocks = ref([])

onMounted(() => {
  const ws = new WebSocket('ws://localhost:8000/ws')

  ws.onmessage = (event) => {
    const data = JSON.parse(event.data)
    stocks.value = data
  }
})
</script>

<style>
h1 {
  text-align: center;
  margin: 20px 0;
}
</style>
